package xxl.config.clock;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.cron.CronUtil;

/**
 * @Author: xixil
 * @Date: 2019/8/15
 */
public class RunReSet {

    public static String M_KEY = "";
    public static String E_KEY = "";

    public void start() {

        System.out.println("re build:" + DateTime.now());

        Integer raMin = RandomUtil.randomInt(45, 59);
        String cron = raMin + " 8 * * 1-5";
        System.out.println("start:" + cron);

        if (StrUtil.isNotBlank(M_KEY)) {
            CronUtil.remove(M_KEY);
        }

        M_KEY = CronUtil.schedule(cron, new Start());
    }

    public void end() {


        Integer raMin = RandomUtil.randomInt(0, 50);
        String cron = raMin + " " + "18" + " * * 1-5";
        System.out.println("end:" + cron);

        if (StrUtil.isNotBlank(E_KEY)) {
            CronUtil.remove(E_KEY);
        }

        E_KEY = CronUtil.schedule(cron, new End());
    }
}
